package ch03_singleton.serializablesingleton;

import java.io.*;

/**
 * 
 *
 * @author guodd
 * @version 1.0 use jdk 1.8
 */
public class HungryBase {
    public static void main(String[] args) throws Exception {
        Hungry01 hungry01 = Hungry01.aa();
        ObjectOutputStream oos = new ObjectOutputStream(new FileOutputStream("abcd"));
        oos.writeObject(hungry01);
        ObjectInputStream ois = new ObjectInputStream(new FileInputStream("abcd"));
        Hungry01 hungry02 = (Hungry01) ois.readObject();
        System.out.println(hungry02 == hungry01);
    }
}

class Hungry01 implements Serializable {
    private Hungry01() {
    }

    private final static Hungry01 aa;

    static {
        aa = new Hungry01();
    }

    public static Hungry01 aa() {
        return aa;
    }

    public Object readResolve() {
        return aa;
    }
}
